package edu.uoc.vmerinom.tfc.backup;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Backup {
	public static void main(String[] args) {
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("tfc-gen-dom");
	    EntityManager entityManager = emf.createEntityManager();
	    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
	    
	    StringBuffer backup = new StringBuffer();
	    
	    backup.append("-- Fichero de respaldo generado ");
	    backup.append(sdf.format(new Date()));
	    backup.append("\n\n-- PERFILES\n");
	    backup.append(Perfiles.backup(entityManager));
	    backup.append("\n-- USUARIOS\n");
		backup.append(Usuarios.backup(entityManager));
		backup.append("\n-- GRUPOS\n");
		backup.append(Grupos.backup(entityManager));
		backup.append("\n-- COMPONENTES\n");
		backup.append(Componentes.backup(entityManager));
		backup.append("\n-- SOLICITUDES\n");
		backup.append(Solicitudes.backup(entityManager));
		backup.append("\n-- REUNIONES\n");
		backup.append(Reuniones.backup(entityManager));
		
		System.out.println(backup);
	}
}
